/*
 * @(#)Object.java   1.0   May 25, 2007
 *
 * Copyright 2000-2007 ETH Zurich. All Rights Reserved.
 *
 * This software is the proprietary information of ETH Zurich.
 * Use is subject to license terms.
 *
 * @(#) $Id: Object.java 456 2007-05-29 09:47:17Z D\aldespin $
 */
package ch.ethz.globis.javaom.minimal;

import java.util.HashMap;
import java.util.Map;

/**
 * @author aldespin
 * @version 1.0
 */
public class Object {

   private Map<Object, Map<Object, Object>> values;

   public Object() {
      this.values = new HashMap<Object, Map<Object, Object>>();
   }

   public void dress(final Object type) {
      if (this.values.containsKey(type)) {
         throw new RuntimeException("this object already has type given");
      }
      // TODO initialise attributes?
      this.values.put(type, new HashMap<Object, Object>());
   }

   public void strip(final Object type) {
      if (!this.values.containsKey(type)) {
         throw new RuntimeException("this object does not have type given");
      }
      this.values.remove(type);
   }

   public void setAttributeValue(final Object type, final Object attribute, final Object value) {
      if (!this.values.containsKey(type)) {
         throw new RuntimeException("this object does not have type given");
      }
      final Map<Object, Object> attributeValues = this.values.get(type);
      // TODO either have attributes initialised while dressing or check here if type declares
      // attribute given
      attributeValues.put(attribute, value);
   }

   public Object getAttributeValue(final Object type, final Object attribute) {
      if (!this.values.containsKey(type)) {
         throw new RuntimeException("this object does not have type given");
      }
      final Map<Object, Object> attributeValues = this.values.get(type);
      if (!attributeValues.containsKey(attribute)) {
         throw new RuntimeException("this object does not have a values for attribute given");
      }
      return attributeValues.get(attribute);
   }
}
